<?php
/**
 * Description of ControllerBase
 * @author HAO SBaseController
 */
class ControllerBase extends CController {
    const FLASH_ERROR 	= 'error';
    const FLASH_NOTICE 	= 'notice';
    const FLASH_SUCCESS = 'success';
    public $layout 		= '//layouts/0-1-0';
    public $menu 		= array();
    public $breadcrumbs = array();
    public $title 		= SITE_NAME;
    public $description = '';
    public $keyword 	= '';
    public $mainTitle 	= '';
    public function init() {
        Yii::app()->language = LOCALE;	}
    public function setFlash($message) {
        Yii::app()->session['flash'] = $message;
    }
    public function getFlash() {
        if ($this->hasFlash()) {
            $message = Yii::app()->session['flash'];
            unset(Yii::app()->session['flash']);
            return $message;
        }
    }
    public function hasFlash($category = self::FLASH_SUCCESS) {
        return Util::user()->hasFlash($category);
    }
    public function renderFlash() {
        $this->getFlash(self::FLASH_SUCCESS);
        $this->getFlash(self::FLASH_NOTICE);
        $this->getFlash(self::FLASH_ERROR);
    }
    public function beforeAction(){//print_r(Yii::app()->controller);exit;
        if (isset(Yii::app()->controller->module) && Yii::app()->controller->module->id == 'admin'){
            if (Yii::app()->user->isGuest) {
                $this->redirect(Yii::app()->createUrl('user/login'));
            }
            $userid 	= Yii::app()->user->id;
            $role 		= Yii::app()->getModule('user')->getRole();
            $actionName = Yii::app()->controller->getAction()->id;
            $role 		= Util::isAllowProcess($userid, $role, 'Brand', $actionName);
            if ($role == 'customer') {
                if (count($role))
                    return true;
                else
                    $this->render('role_limit');			}
            return true;
        }        else
            return true;
    }
}